package com.infolab.aims.domain.asset;

import java.io.Serializable;

import javax.persistence.Embeddable;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import org.apache.commons.lang.StringUtils;

@Embeddable
public class AssetEquipmentPK implements Serializable {
	
	@ManyToOne
	@JoinColumn(name="assetModelId")
	private AssetModel assetModel;
	
	private String serialNo;
	
	public AssetEquipmentPK() {
	
	}
	public AssetEquipmentPK(AssetModel assetModel,String serialNo) {
		this.assetModel=assetModel;
		this.serialNo=serialNo;
	}
	
	public AssetModel getAssetModel() {
		return assetModel;
	}

	public void setAssetModel(AssetModel assetModel) {
		this.assetModel = assetModel;
	}

	public String getSerialNo() {
		return serialNo;
	}

	public void setSerialNo(String serialNo) {
		this.serialNo = serialNo;
	}

	@Override
	public boolean equals(Object obj) {
		if(obj == null) return false;
		if(obj instanceof AssetEquipmentPK)
		{
			AssetEquipmentPK tmp = (AssetEquipmentPK)obj;
			
			return StringUtils.equalsIgnoreCase(serialNo, tmp.getSerialNo()) && 
					assetModel.equals(tmp.getAssetModel());
		}
		else
			return false;
	}
	@Override
	public int hashCode() {
		if(serialNo==null || assetModel == null ){
			return super.hashCode();
		}else{
			final int PRIME = 31;
		    int hashCode = 1;
		    hashCode = PRIME * hashCode + serialNo.hashCode();
		    hashCode = PRIME * hashCode + assetModel.hashCode();
		    return hashCode;
		}
	}
	

}
